package com.achilles.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.achilles.bean.DataBean;
import com.achilles.callback.IProjectOrGiftDialogItemClick;
import com.achilles.playtask.R;
import com.achilles.utils.DisplayUtils;

/**
 * Created by AchillesL on 2016/10/2.
 */

public class RevertItemDialog {
    private AlertDialog mAlertDialog;
    private IProjectOrGiftDialogItemClick mIProjectOrGiftDialogItemClick;
    private DataBean mClickDataBean;
    private IRevertItemDialogStatus IRevertItemDialogStatus;

    public interface IRevertItemDialogStatus {
        void onDeleteClick(DataBean dataBean);
    }

    public RevertItemDialog(Context context) {
        TextView textView = generateTextView(context);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(textView);
        mAlertDialog = builder.create();
    }

    @NonNull
    private TextView generateTextView(Context context) {
        TextView textView = (TextView) LayoutInflater.from(context).inflate(R.layout.rippe_textview,null);
        int topBottomPadding = (int) DisplayUtils.dp2px(10, context);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
        textView.setPadding(0,topBottomPadding,0,topBottomPadding);
        textView.setText(R.string.revert);
        textView.setGravity(Gravity.CENTER);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (IRevertItemDialogStatus != null) {
                    IRevertItemDialogStatus.onDeleteClick(mClickDataBean);
                }
            }
        });
        return textView;
    }

    public void setIRevertItemDialogStatus(IRevertItemDialogStatus IRevertItemDialogStatus) {
        this.IRevertItemDialogStatus = IRevertItemDialogStatus;
    }

    public void show(DataBean dataBean) {
        mClickDataBean = dataBean;
        mAlertDialog.show();
    }

    public void dismiss() {
        mAlertDialog.dismiss();
    }
}
